{% extends 'templates/default_template.html' %}
{%block content%}
<h1>New Request</h1>
<p>You are requesting a new instances of the workflow {{workflow.name}}. Please fill in the fields for elevating the request.</p>
<form action="" method="post" id="requestForm">
  <label for="requestor">Requestor</label><p name="requestor">{{logged_user.name}}</p>
  
  <label for="name">Request name</label><input type="text" name="name" value="{{workflow.name}}" />
  <label for="origin">Origin</label><input type="text" name="origin" value="{{workflow.project.default_origin}}"/>
  <label for="destination">Destination</label><input type="text" name="destination" value="{{workflow.project.default_destination}}"/>
  <label for="files_changed" class="tip1"  rel="You can write down the filenames one per line or pass a SVN commit log" title="Changed Files">Files changed</label>
  
  <textarea name="files_changed" cols="80" rows="5" id="files_changed"></textarea>
  <div>
    <ul id="files_changed_list"></ul>
  </div>
  <label for="required_commands">Required commands</label><textarea name="required_commands" cols="80" rows="5" id="required_commands"></textarea>
  <div>
    <ul id="required_commands_list"></ul>
  </div>
  <label for="comment">Comment</label><textarea name="comment" cols="80" rows="5" id="comment"></textarea>
  <br />
  <input type="submit" value="Request" />
</form>
{%endblock content%}

{%block js_activities %}
<script type="text/javascript">
function replaceContentForStringList()
{
  
  var textarea = this;
  var text = textarea.value;
  var texts = text.split('\n');
  var list = document.id(this.id + '_list');
  var separate = function(text,textlist){ textlist.append(text.split(','));};
  var sepRegex = /\w+\s+[\(bin\)]*\s+(.*)/;
  var requestForm = document.id('requestForm');
  for(var i = 0; i < texts.length; i++)
  {
    var el = texts[i].replace(sepRegex,'$1');
    if(el != ""){
      list.grab(new Element('li',{'text':el}));
      requestForm.grab(new Element('input',{'type':'hidden','name':this.id+"_values",'value':el}));
    }
  }
  textarea.value ='';
  
  
}

</script>
{%endblock js_activities %}
{%block domready%}
var myTips = new Tips($$('.tip1'));
document.id('files_changed').addEvent('blur',replaceContentForStringList);
document.id('required_commands').addEvent('blur',replaceContentForStringList);
{%endblock domready%}